package net.awpspace.walkman.entity;

/**
 * Entity: MP3 file
 * 
 * @author Diep AwpSpace
 * 
 */
public class MP3 {

	public int id;
	public String filePath;
	public String title;
	public String artist;
	public String album;

	public MP3(int id, String filePath, String title, String artist, String album) {
		this.id = id;
		this.filePath = filePath;
		this.title = title;
		this.artist = artist;
		this.album = album;
	}

	/**
	 * Get MP3 entity from string source
	 * 
	 * @param source
	 * @return
	 */
	public static MP3 parseFromString(String source) {
		int index = source.indexOf('|');
		int id = Integer.parseInt(source.substring(0, index));
		source = source.substring(index + 1);

		index = source.indexOf('|');
		String filePath = source.substring(0, index);
		source = source.substring(index + 1);

		index = source.indexOf('|');
		String title = source.substring(0, index);
		source = source.substring(index + 1);

		index = source.indexOf('|');
		String artist = source.substring(0, index);
		source = source.substring(index + 1);
		
		index = source.indexOf('|');
		String album = source.substring(0, index);
		source = source.substring(index + 1);

		return new MP3(id, filePath, title, artist, album);
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(id);
		buffer.append('|');
		buffer.append(filePath);
		buffer.append('|');
		buffer.append(title);
		buffer.append('|');
		buffer.append(artist);
		buffer.append('|');
		buffer.append(album);
		return buffer.toString();
	}
}
